<?php

namespace app\api\controller;

use app\admin\model\Captcha;
use app\admin\model\Members;
use app\home\validate\Reg;

use think\Cache;
use think\Config;
use think\Controller;
use think\Db;
use think\Request;

/**
 * 支付相关
 */
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');
class Recharge extends Base
{
    public function _initialize()
    {
        $uid = \request()->post('uid');
        $token = \request()->post('token');
        check_token($uid, $token);
    }

    /**
     * 获取线下充值二维码
     */
    public function get_offline_qrcode(){
        $data = Db::name('qrcode')->select();
        foreach ($data as $k=>$v){
            $data[$k]['qrcode'] = Config::get('img_url').$v['qrcode'];
        }
        json_return(200,'获取二维码成功',$data);
    }

    /**
     * 线下充值
     */
    public function offline_charge(Request $request){
        $uid      = $request->post('uid');
        $money    = $request->post('money');
        $name     = $request->post('name');
        $remark   = $request->post('remark');
        $way      = $request->post('way');
        if(!$uid || !$name || !$money || !$remark  ){
            json_return(204,'缺少参数');
        }
        if($way==1){
            $up['wx_qrcode'] = $name;
        }
        if($way==2){
            $up['alipay']        = $name;
        }
        $charge['way']    = $way;
        $charge['uid']    = $uid;
        $charge['money']  =  $money;
        $charge['name']   = $name;
        $charge['type']   = 2;
        $charge['remark'] = $remark;
        $charge['create_at'] = time();
        $result = Db::name('recharge')->insert($charge);
        if($result){
            json_return(200,'提交成功，等待后台审核');
        }else{
            json_return(500,'提交失败');
        }

    }









}